package com.shop.admin.controller;

import com.shop.admin.result.ApiResult;
import com.shop.admin.service.ShopUserService;
import com.shop.admin.utils.PageUtils;
import com.shop.admin.valid.UpdateGroup;
import com.shop.admin.vo.UserStatusVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = {"ShopUserController"},description = "用户接口")
@RestController
@RequestMapping("/api/user")
public class ShopUserController {

    @Resource
    private ShopUserService userService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "get用户列表",notes = "page,limit,key封装用户id或用户昵称，用户账号,手机号，状态")
    public ApiResult list(@ApiParam("参数为：page,limit,key,userName,phonenumber，status")@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);
        return ApiResult.ok(page);
    }

    /**
     * 修改状态
     */
    @PostMapping("/update/status")
    @ApiOperation(value = "修改状态",notes = "状态，用户id")
    public ApiResult update(@ApiParam("参数为：status，userId")@Validated(UpdateGroup.class) @RequestBody UserStatusVo vo){
        userService.updateStatus(vo);
        return ApiResult.ok("修改成功！");
    }
}
